
import { BaseService } from '@src/service/base/base.service';
import { Injectable, HttpException, HttpStatus, Request } from '@nestjs/common';
import { InjectRepository } from '@nestjs/typeorm';
import { Repository } from 'typeorm';
import { LoggerEntity } from '@src/entities/sys/logger.entity';

@Injectable()
export class LoggerService extends BaseService {
  constructor(
    @InjectRepository(LoggerEntity)
    private readonly loggerRepository: Repository<LoggerEntity>,

  ) {
    super(loggerRepository)
  }

  /**
 * 记录日志
 * @memberof RoleService
 */
  public async logger(request: any): Promise<void> {
    const { referer, origin, host } = request.headers;
    const { username } = request.body;
    const data = {
      address: referer,
      name: username,
      ip: origin,
      brower: request.headers['user-agent']
    }
    const log = await this.loggerRepository.create(data);
    this.loggerRepository.save(log);
  }
}